
VERSION = "0.60"
NAME = "breemlib"

CC = gcc
CXX = g++
LD = g++
AR = ar

OUTPUT = libbreemlib.a

CFLAGS = -DLOGGER -I. -g
#CFLAGS += -DWIN32 -DWIN32GUI
CFLAGS += -DLINUX -DSDL
CXXFLAGS = $(CFLAGS)
LDFLAGS =
LIBS = -lz
#LIBS += -lkernel32 -lshell32 -lshfolder -lgdi32 -ldxguid -lddraw
LIBS += -lSDL -lSDLmain
MAKEDEPEND = g++ -M $(CPPFLAGS) -o $*.d $<

SOURCE = 6821.cpp Params.cpp Settings.cpp Watchdog.cpp hq2x.cpp \
	Filters.cpp Rom.cpp State.cpp breemlib.cpp input.cpp \
	Machine.cpp RomSet.cpp StdAfx.cpp crc32.cpp list.cpp \
	apu/DAC.cpp apu/ay8910/ay8910.cpp apu/hc55516/hc55516.cpp \
	apu/msm5205/msm5205.cpp apu/ym2151/ym2151.cpp \
	cpu/6502.cpp cpu/Dead6502v4.cpp cpu/Dead6502v3.cpp cpu/CPU.cpp \
	cpu/dead6309/Dead6309.cpp cpu/dead63701/Dead63701.cpp \
	cpu/dead6502/dead6502.c cpu/dead6502v4/cpu6502.cpp \
	cpu/dead6800/Dead6800.cpp cpu/dead6808/Dead6808.cpp \
	cpu/dead6809/Dead6809.cpp cpu/deadz80/deadz80.cpp \
	unzip/zcrc32.cpp unzip/unzip.cpp unzip/infutil.cpp unzip/zutil.cpp \
	unzip/infblock.cpp unzip/inflate.cpp unzip/inffast.cpp \
	unzip/infcodes.cpp unzip/inftrees.cpp unzip/adler32.cpp

SDLSOURCE = SDLSound.cpp SDLInput.cpp SDLVideo.cpp

FLTSOURCE = system/sdl/scale2x/scalebit.c system/sdl/scale2x/scale2x.c system/sdl/scale2x/scale3x.c
FLTSOURCE += system/sdl/hq2x/hq2x.c system/sdl/hq2x/hq3x.c
FLTSOURCE += system/sdl/interpolate/interpolate.c system/sdl/draw/draw.c

LNXSOURCE =
W32SOURCE =

SOURCE += $(LNXSOURCE) $(SDLSOURCE)

CSOURCE = $(filter %.c,$(SOURCE))
CXXSOURCE = $(filter %.cpp,$(SOURCE))

OBJECT = $(sort $(CSOURCE:.c=.o) $(CXXSOURCE:.cpp=.o))

%.P: %.c
	$(MAKEDEPEND)
	@sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' < $*.d > $@; \
		rm -f $*.d; [ -s $@ ] || rm -f $@

#include $(OBJECT:.o=.P)

$(OUTPUT): $(OBJECT)
#	$(LD) -o $@ $(LDFLAGS) $(OBJECT) $(LIBS)
	$(AR) r $@ $(OBJECT)
all: version.h $(OUTPUT)

clean:
	rm -rf $(OUTPUT) $(OBJECT)

cleancpu:
	rm -rf $(OUTPUT) pce/cpu/hu6280.o pce/cpu/hu6280_disasm.o

version.h:
	rm -rf $@
	echo "#ifndef __version_h__" >> $@
	echo "#define __version_h__" >> $@
	echo "#define VERSION \"$(VERSION)\"" >> $@
	echo "#define APPNAME \"$(NAME)\"" >> $@
#	echo "#define APPCLASSNAME \"$(NAME)CLASSNAME\"" >> $@
	echo "#endif" >> version.h

#system/win32/pceemu-res.o:
#	windres -Isystem/win32 $(@D)/pceemu.rc $@

TESTROM = test.pce
#keith.pce

run: all
	$(OUTPUT) $(TESTROM)
        
gdb: all
	gdb $(OUTPUT) -ex "run cart.pce"
